<?php
session_start();
include "mysqli_connection.php";

if (!isset($_SESSION["username"])){
	echo "<script>window.location.href='login.php'</script>";
}
else{
	$query = "SELECT Requirement_Program.r_id, Requirements.name FROM Requirement_Program INNER JOIN Requirements WHERE (p_id = ? ) AND (Requirements.r_id = Requirement_Program.r_id);";
	$stmt = $mysqli->stmt_init();
	if ($stmt = $mysqli->prepare($query)){
		$stmt->bind_param("i", trim($_POST["p_id"]));
		$stmt->execute();
		$stmt->bind_result($r_id, $name);
	}
	$text = "";
	if (isset($stmt)){
		while ($stmt->fetch()){
			if ($text === ""){
				$text .= "<div><ul>";
			}
			$text .= "<li><a href = 'managerequirements.php?index=" . $r_id . "'>" . $name . "</a></li>";
		}
		$stmt->close();
	}
	if ($text !== ""){
		echo $text . "</ul></div>";
	}
	else{
		echo "<div>No requirements</div>";
	}
}